﻿using GEG.NGCRM.Event.Domain.SendEvent;
using GEG.NGCRM.Event.Domain.Share.Config;
using LJ.Abstractions.Config;
using LJ.WebApi.Abstractions;
using LJ.WebApi.Abstractions.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GEG.NGCRM.Event.Application.SendEvent;

[WebApiHandler("Send", "Event", WebApiType.Post)]
public class SendEventWebApiHandler(IConfigProvider configProvider,IWebApiContext webApiContext, SendEventDomain sendEventDomain) : IWebApiRouteHandler<string>
{
    private readonly EventConfig eventConfig= configProvider.Get<EventConfig>();
    private readonly IWebApiContext _webApiContext= webApiContext;
    private readonly SendEventDomain _sendEventDomain = sendEventDomain;
    public async Task ExecuteAsync(string route)
    {
        if (eventConfig.SendEventDict.TryGetValue(route, out var value))
        {
            var body = await _webApiContext.GetBodyAsync();

            await _sendEventDomain.SendAsync(value, body);
        };
    }
}
